package com.esdk.log;

import com.esdk.esdk;

import java.util.Map;

public class DefaultLayout implements ILogFormater{
  private static String layoutPattern=esdk.prop.get("LogLayoutPattern","{Time}{Space}[{Name}{Space}{Level}]{Caller}{Space}{Msg}{End}");
  public DefaultLayout(){}

  public ILogItem format(ILogItem item){
    Map<Object,Object> params=Map.of("Time",item.getTime(),"Name",item.getName(),"Level",item.getLevel()
      ,"Caller",esdk.tool.getCaller(item.getLevel().getLevel()<=DefaultLogLevel._ERROR?esdk.tool.InfoCallerTemplate:esdk.tool.ErrorCallerTemplate,5),"Msg",item.getContent()
    ,"Space",item.getDelimiter(),"End",item.getEndChar());
    item.setResult(esdk.str.format(layoutPattern,params));
    return item;
  }
}
